package com.lagou.filter;

import com.lagou.bean.ExecTime;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.LinkedList;
@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {
    public static LinkedList<ExecTime> queue1=new LinkedList();
    public static LinkedList<ExecTime> queue2=new LinkedList();

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long  startTime  = System.currentTimeMillis();
        try {
            // 执行方法
            return  invoker.invoke(invocation);
        } finally {
            long endTime = System.currentTimeMillis();
            //推送到消息队列
            String methodName = invocation.getMethodName();
            ExecTime execTime = new ExecTime(endTime, endTime - startTime);
            if("sayHelloOne".equals(methodName)){
                queue1.add(execTime);
            }else if("sayHelloTwo".equals(methodName)){
                queue2.add(execTime);
            }

        }

    }

}
